package com.example.tts.controller;

import com.example.tts.entity.URL;
import com.example.tts.service.ICrawlingService;
import com.example.tts.service.impl.CSDNCrawlingService;
import com.example.tts.service.impl.Mp3Service;
import com.example.tts.service.impl.WXCrawlingService;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.FileInputStream;
import java.io.IOException;
import java.sql.Blob;
import java.sql.SQLException;


/**
 * @ClassName WorldBankCrawl
 * @Description TODO
 * @Author 韩兴隆
 * @Date 2021/11/23 15:02
 **/
@Controller
@RequestMapping("crawl")
public class WorldBankCrawl {
    @Autowired
    Mp3Service mp3Service;
    ICrawlingService crawling;
    @ResponseBody
    @GetMapping("crawling")
    public URL crawling(@RequestParam String url) throws IOException, SQLException {
        URL Url = new URL();
        String[] str = url.split("\\.");
        switch(str[1]+str[2]){
            case "weixinqq":
                crawling=new WXCrawlingService();
                break;
            case "blogcsdn":
                crawling=new CSDNCrawlingService();
                break;
            default:
                return null;
        }
        Url.setUrl(url);
        Url.setText(crawling.crawling(url));
        Url.setSrc(url+".mp3");
        return Url;
    }

}
